

import java.util.ArrayList;
import java.util.Scanner;

public class AdminTest {
    public static void main(String[] args) {
        ArrayList<Admin.CustomerManagement> list;
        list = new ArrayList<>();
        Admin admin = new Admin();
        admin.LoginPassword();
        String password = "mySecurePassword";
        loop: while (true) {
            System.out.println("--------------客户信息管理--------------");
            System.out.println("1:添加用户");
            System.out.println("2:删除用户");
            System.out.println("3:修改用户");
            System.out.println("4:查询用户");
            System.out.println("5:退出系统");
            System.out.println("请输入你的选择");
            Scanner cs = new Scanner(System.in);
            String choose = cs.next();
            switch (choose) {
                case "1":
                    adduser(list);
                    break;
                case "2":
                    deleteUser(list);
                    break;
                case "3":
                    updateUser(list);
                    break;
                case "4":
                    queryUser(list);
                    break;
                case "5":
                    System.out.println("5:退出系统");
                    break loop;

                default:
                    System.out.println("输入有误");
                    break;
            }



        }


    }

    public static void adduser(ArrayList<Admin.CustomerManagement> list) {


        Scanner cs = new Scanner(System.in);
        System.out.println("请输入用户的id");
        String id = cs.next();
        System.out.println("请输入用户名");
        String userName = cs.next();
        System.out.println("请输入用户级别");
        String grade = cs.next();
        System.out.println("请输入用户注册时间");
        String useTime = cs.next();
        System.out.println("请输入用户消费金额");
        String consumption = cs.next();
        System.out.println("请输入用户手机号");
        String phoneNumber = cs.next();
        System.out.println("请输入用户邮箱");
        String Ebox = cs.next();
        Admin.CustomerManagement s= new Admin.CustomerManagement(id, userName, grade, useTime, consumption, phoneNumber, Ebox);

//添加用户对象

        list.add(s);


        System.out.println("添加用户信息成功");
    }
    public static void deleteUser(ArrayList<Admin.CustomerManagement> list) {
        Scanner cs = new Scanner(System.in);
        System.out.println("是否删除该用户（输入删除用户的id）");
        String id = cs.next();
        if (list.size() != 0) {
            Admin.CustomerManagement s= list.get(0);
            list.remove(s);
        }
        System.out.println("用户已删除");
    }

    public static void updateUser(ArrayList<Admin.CustomerManagement> list) {
        Scanner cs = new Scanner(System.in);
        System.out.println("请输入要修改的用户的的id:");
        String id = cs.next();
        int index = 0;
        getIndex(list, id);
        if (index == -1) {
            System.out.println("要修改的" + id + "不存在，请重新输入");
            return;
        }
        //获取要修改的商品对象
        Admin.CustomerManagement stu = list.get(index);
        //输入其他信息并修改
        System.out.println("请输入要修改的用户名");
        String newname = cs.next();
        System.out.println("请输入要修改的用户级别");
        String grade = cs.next();
        System.out.println("请输入要修改的用户注册时间");
        String useTime = cs.next();
        System.out.println("请输入要修改的用户消费金额");
        String consumption = cs.next();
        System.out.println("请输入要修改的用户手机号");
        String phoneNumber = cs.next();
        System.out.println("请输入要修改的用户邮箱");
        String Ebox = cs.next();
        System.out.println("用户修稿信息成功");
    }


    public static void queryUser(ArrayList<Admin.CustomerManagement> list) {
        if (list.size() == 0) {
            System.out.println("当前无用户信息，请添加后查询");
            return;
        }

        //集合中有数据 ，打印表头信息
        System.out.println("id\t\t用户名\t用户级别\t用户注册时间\t用户消费金额\t用户手机号\t用户邮箱");
        int i;
        for (i = 0; i < list.size(); i++) {
            Admin.CustomerManagement stu = list.get(i);
            System.out.println(stu.getId() + "\t"  + stu.getUsername()+"\t"+ stu.getGrade() + "\t" + stu.getRegistrationTime() + "\t" + stu.getSpendAmount() + "\t" + stu.getPhoneNumber() + "\t" + stu.getMailbox());
        }


    }
    public static boolean contions(ArrayList<Admin.CustomerManagement> list, String id) {
        //循环遍历集合
        //     for (int i = 0; i < list.size(); i++) {
        // Admin.Store stu = list.get(i);
        //  String sid = stu.getId();
        //   if (stu.getId().equals(id)) {
        //     return true;
        //     }
        //   }
        //  return false;
        return getIndex(list,id)>=0;
    }

    //通过id获取索引
    public static int getIndex(ArrayList<Admin.CustomerManagement> list, String id) {
        for (int i = 0; i < list.size(); i++) {
            Admin.CustomerManagement stu = list.get(i);
            String sid = stu.getId();
            if (stu.getId().equals(id)) {
                return i;

            }
        }
        return -1;

    }










}

